//init variables
PXS_SatelliteInitialHeight = 900;
PXS_SatelliteFOV = 0.2;
PXS_SatelliteZoom = 12.4;
PXS_SatelliteNorthMovementDelta = 0;
PXS_SatelliteSouthMovementDelta = 0;
PXS_SatelliteEastMovementDelta = 0;
PXS_SatelliteWestMovementDelta = 0;
PXS_ViewDistance = 0;
PXS_RequestInterval = 300;

if (isnil "PAPABEAR") then { PAPABEAR = [playerSide,"HQ"]; };

if (isnil "PXS_LastRequest") then {
	PXS_LastRequest = time - PXS_RequestInterval;
};
if ((time - PXS_LastRequest) < PXS_RequestInterval) exitWith {
	PAPABEAR sideChat format [localize "STR_PXS_WAIT",(floor(PXS_RequestInterval - (time - PXS_LastRequest))) max 3, group player];
};

PXS_Delay = {
    //Custom delay
	PAPABEAR sideChat format [localize "STR_PXS_TRANSMITTED", group player];
	sleep 3 + random 4;
	PAPABEAR sideChat format [localize "STR_PXS_ALIGNING", group player];
	sleep 20;
    PAPABEAR sideChat format [localize "STR_PXS_ALIGNED", group player];
    sleep random 5;
    for "_i" from 0 to 4 do {
    	_cnt = 5 - _i;
        hint format [localize "STR_PXS_READYIN",_cnt];
        sleep 1;
        if (_cnt == 1) then {hint format [localize "STR_PXS_READY",_cnt]};
    };
    sleep 1;
	PXS_LastRequest = time;
    
    call PXS_viewSatellite;
	[4] call PXS_adjustCamera;
};

["PXS_SAT_COM_EVT_ID", "onMapSingleClick", {
    if ((player distance _pos) < 2000) then {
        ["PXS_SAT_COM_EVT_ID", "onMapSingleClick"] call BIS_fnc_removeStackedEventHandler;
		PXS_SatelliteTarget = "Logic" createVehicleLocal _pos;
		PXS_SatelliteTarget setDir 0;
        [] spawn PXS_Delay;
        openMap false;
	} else {
        if (true) exitwith {
            hint localize "STR_PXS_VIEWLIMIT";
        };
	};
}] call BIS_fnc_addStackedEventHandler;

hint localize "STR_PXS_HINT";
openMap true;